package com.hmall.api.item.interceptors;

import com.hmall.common.utils.UserContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

/**
 * @author: lxr
 * @Date: 2025/09/06 14:38
 * @Description:
 */
@Slf4j
public class FeignInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        Long userId = UserContext.getUser();
        log.warn("feign拦截器，用户id为：{}", userId);
        if (Objects.nonNull(userId)) {
            requestTemplate.header("user-info", userId.toString());
        }
    }
}
